package com.yang.lesson03;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestWindow {
    public static void main(String[] args) {
        new WindowFrame();
    }
}

class WindowFrame extends Frame{
    public WindowFrame() {
        setBackground(Color.pink);
        setBounds(100,100,200,200);
        setVisible(true);

        this.addWindowListener(new WindowAdapter() {
            //关闭窗口
            @Override
            public void windowClosing(WindowEvent e) {
                System.out.println("窗口已关闭");
                System.exit(0);
            }

            //激活窗口
            @Override
            public void windowActivated(WindowEvent e) {
                Object source=e.getSource();
                System.out.println("窗口已激活");
            }

        });
    }
}